import React, { Component } from 'react'
import { Route, Redirect } from 'react-router-dom'
import { hasToken } from 'utils/storage'

export class AuthRoute extends Component {
    render() {
        // console.log(this.props);
        const {component:Component, ...rest} = this.props
        // console.log(rest)
        return <Route {...rest} render={(RouteProps)=> {
            // console.log('AuthRoute',this.props)
            if(hasToken()) {
                return <Component {...RouteProps}/>
            } else {
                return <Redirect to={{
                    pathname:'/login',
                    state:{
                        from:RouteProps.location.pathname
                    }
                }}/>
            }
        }}></Route>
    }
}

export default AuthRoute